package com.qf.shiro2302.controller;

import com.qf.shiro2302.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {

//    @RequiresRoles({"admin","test"})
    @RequiresPermissions("user:get")
    @GetMapping("/test1")
    public String test1(){
        return "hello shiro from test1";
    }


    @GetMapping("/test2")
    public User test2(){
        // 如何使用shiro获取当前登录用户的身份信息
        Subject subject = SecurityUtils.getSubject();
        User principal = (User) subject.getPrincipal();
        System.out.println(principal);
        return principal;

    }

}
